@extends('layouts.app')

@section('title', '订单列表')

@section('css-import')
<link href="{{config('app.inlet_src')}}/assets/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
@endsection

@section('css-write')
<style type="text/css">
	.page-s{
		display: inline-block;
		padding-bottom: 0px;
		margin: 29px 9px;
		border-radius: 4px;
		float:  right;
	}
</style>
@endsection

@section('content-fluid')
<div class="row">
	<!-- BASIC TABLE -->
	<div class="panel">
		<div class="panel-heading">
			<h3 class="panel-title">乐享订单</h3>
		</div>
		<div class="panel-body">
			<ul class="nav nav-pills" style="float:left;">
			  <li role="presentation" class="orderall">
			  	<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
			      取餐状态 <span class="caret"></span>
			    </a>
			    <ul class="dropdown-menu">
			      <li role="presentation" class="yiqucan"><a href="">已取餐</a></li>
			      <li role="presentation" class="weiqucan"><a href="">未取餐</a></li>
			      <li role="presentation" class="yichaoshi"><a href="">已超时</a></li>
			    </ul>
			  </li>
			  <li role="presentation" class="orderall">
			  	<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
			      是否打包 <span class="caret"></span>
			    </a>
			    <ul class="dropdown-menu">
			      <li role="presentation" class=""><a href="">打包</a></li>
			      <li role="presentation" class=""><a href="">不打包</a></li>
			    </ul>
			  </li>
			  <li role="presentation" class="orderall"><a href="">全部</a></li>
			</ul>
			<div class="input-group date form_datetime col-md-2" data-date="{{date('Y-m-d H:i')}}" data-date-format="yyyy-mm-dd hh:ii" data-link-field="dtp_input1" style="float:left; margin-left:25px;">
			    <input class="form-control" size="16" type="text" value="{{$_GET['starttime'] ?? ''}}" name="starttime" placeholder="筛选从...开始" readonly>
			    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
				<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
			</div>
			<div class="input-group date form_datetime col-md-2" data-date="{{date('Y-m-d H:i')}}" data-date-format="yyyy-mm-dd hh:ii" data-link-field="dtp_input1" style="float:left; margin-left:20px;">
			    <input class="form-control" size="16" type="text" value="{{$_GET['endtime'] ?? ''}}" name="endtime" placeholder="筛选到...结束" readonly>
			    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
				<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
			</div>
			<form action="/orderListAll" method="get" id="searchFormOrder">
				<div class="input-group col-md-4 pull-right" style="z-index: auto;">
					<input type="text" value="{{$_GET['keyword'] ?? ''}}" class="form-control app-search-text" name="keyword" AUTOCOMPLETE="off" placeholder="搜索手机号或微信昵称">
					@foreach($_GET as $k=>$v)
					@if($k!='page' && $k!='keyword')
					<input type="hidden" value="{{$v}}" name="{{$k}}">
					@endif
					@endforeach
					<span class="input-group-btn"><button type="submit" class="btn btn-primary search-jslx"><i class="fa fa-search"></i></button></span>
				</div>
			</form>
			<table class="table table-hover">
				<thead>
					<tr>
						<th>#</th>
						<th>订单号</th>
						<th>流水号</th>
						<th>下单用户</th>
						<th>隶属店铺</th>
						<th>餐品</th>
						<th>消费金额</th>
						<th>下单时间</th>
						<th>订单状态</th>
						<th>下单方式</th>
					</tr>
				</thead>
				<tbody>
					@foreach($orders as $k=>$v)
					<tr>
						<td>{{$v->order_id}}</td>
						<td>{{$v->order_number}}</td>
						<td>{{$v->order_sernum}}</td>
						<td><a href="/user-details?userid={{$v->users_id}}">{{$v->nicename ?? '未填写'}}</a></td>
						<td><a href="/shopDetails?shopid={{$v->shops_id}}">{{$v->shop_name}}</a></td>
						<td>{{$v->cateslist}}</td>
						<td>{{$v->meal_order_price}} 元</td>
						<td>{{$v->insert_time}}</td>
						@if($v->order_status==3)
						<td>{{$orderstatus_de[$v->order_status]}}</td>
						@else
						<td class="orderstatus">{{$orderstatus_de[$v->order_status]}}@if($v->order_status != '-2')· <a href="javascript:void(0)" onclick="cancelOrder('{{$v->order_id}}',this)">撤销订单</a>@endif</td>
						@endif
						<td>{{$qc_de[$v->order_type]}}{!!empty($v->help_user_name)?'':'/<a href="/user-details?userid='.$v->help_user_id.'">'.$v->help_user_name.'</a>'!!}</td>
					</tr>
					@endforeach
				</tbody>
			</table>
			{{ $orders->appends(['keyword'=>$_GET['keyword'] ?? ''])->links() }} 
			<div class="page-s">本页共{{ $orders->count() }}条</div>
			<div class="page-s">共{{ $orders->total() }}条</div>
			<div class="page-s">当前第{{ $orders->currentPage() }}页</div>
			<div class="page-s">共{{ $orders->lastPage() }}页</div>
		</div>
	</div>
	<!-- END BASIC TABLE -->
</div>
@endsection

@section('js-import')
<script src="{{config('app.inlet_src')}}/assets/scripts/bootstrap-datetimepicker.js"></script>
<script src="{{config('app.inlet_src')}}/assets/scripts/bootstrap-datetimepicker.zh-CN.js"></script>
@endsection

@section('js-write')
<script type="text/javascript">
	$('#searchFormOrder').attr('action',location.pathname);
	$('.form_datetime').datetimepicker({
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0,
        showMeridian: 1
    });
    function cancelOrder(orderid,this_) {

		swal({
	 	 title: '确定撤回该订单吗？', 
		  text: '操作将返还用户的消费次数，并扣除店铺收入。', 
		  type: 'question',
		  showCancelButton: true, 
		  confirmButtonColor: '#3085d6',
		  cancelButtonColor: '#d33',
		  confirmButtonText: '确定', 
		  cancelButtonText: '取消',
		  confirmButtonClass: 'btn btn-success',
		  cancelButtonClass: 'btn btn-danger',
		  buttonsStyling: true
		}).then(function(al) {
			if(al.value){
				$.ajaxSetup({
				    headers: {
				        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
				    }
				});
				$.post('/cancel-order',{'order_id':orderid},function(response){
					if(response.success){
						$(this_).parents('.orderstatus').text("取消订单");
						toastr.success(response.message);
					}else{
						toastr.error(response.message);
					}
				},'json');	
			}
		});
	}
</script>
@endsection